//
//  UIViewControllerExtension.swift
//  ExtremeHealth
//
//  Created by Zhongkai Li 李忠凯 on 2018/9/10.
//  Copyright © 2018 GanDongKeJi. All rights reserved.
//

import UIKit

extension UIViewController {
    func hideNavibar(animated: Bool = true) {
        navigationController?.setNavigationBarHidden(true, animated: animated)
    }

    func showNavibar(animated: Bool = true) {
        navigationController?.setNavigationBarHidden(false, animated: animated)
    }

    func withBack(imageName: String = "white_back") {
        let backButton = UIButton(type: .custom)
        backButton.frame = CGRect(origin: .zero, size: CGSize(width: 34, height: 34))
        backButton.setImage(UIImage(named: imageName), for: .normal)
        backButton.addTarget(self, action: #selector(naviPop), for: .touchUpInside)
        let backBarButtonItem = UIBarButtonItem(customView: backButton)
        navigationItem.leftBarButtonItem = backBarButtonItem
    }

    @objc private func naviPop() {
        navigationController?.popViewController(animated: true)
    }
}

extension UINavigationController {
    func hideHairLine() {
        navigationBar.shadowImage = UIImage()
        navigationBar.setBackgroundImage(UIImage(), for: .default)
        view.backgroundColor = .clear
        navigationBar.backgroundColor = UIColor.clear
    }
}
